--编写者：alt
--功能介绍：替换克雷的only used by 的话

--替换克雷的only used by 的话
local charactername = {
    "wilson", "willow", "wolfgang", "wendy", "wx78", "wickerbottom", "woodie", "wes", "waxwell", "wathgrithr", "webber",
    "winona", "warly", "walter"
}
local function TraceWithStack(character, root, tab, path)
    local stack = { { tab, path } }
    while #stack > 0 do
        local curtbl, curpath = unpack(table.remove(stack))
        for k, v in pairs(curtbl) do
            if type(v) == "table" then
                table.insert(curpath, k)
                table.insert(stack, { v, { unpack(curpath) } })
                table.remove(curpath)
            else
                for k2, v2 in pairs(root) do
                    if k2 ~= curpath[1] then
                        local data = v2
                        for i = 2, #curpath do
                            data = data[curpath[i]]
                            if not data then break end
                        end
                        if type(data) == "table" then
                            if data[k] == "only_used_by_" .. string.lower(character) then
                                data[k] = v
                            end
                        end
                    end
                end
            end
        end
    end
end
for _, p in ipairs(charactername) do
    local character = string.upper(p)
    local tab = STRINGS
    local stack = { { tab } }
    while #stack > 0 do
        local curtbl = table.remove(stack)
        for k, v in pairs(curtbl) do
            if type(v) == "table" then
                if v[character] and type(v[character]) == "table" then
                    TraceWithStack(character, v, v[character], { character })
                else
                    table.insert(stack, v)
                end
            end
        end
    end
end
